<?php
class rbacControl extends control{

	function role_set(){//角色设置

	$this->display();
	}
	function role_add(){//添加角色
		$db=M("role");
		if($db->add()){
			$this->success("角色添加成功");
		}else{
			$this->error("角色添加失败");
		}
	}
	function role_show(){//角色显示
		$db=M("role");
		$row=$db->all();
		$this->assign("row",$row);
		$this->display();
	}
	function role_add_show(){
		$this->display();
	}
	function user_role_add_show(){
		C("debug",1);
		$uid=$_GET['uid'];
		$this->assign("uid",$uid);
		$db=M("role");
		$row=$db->all();
		$this->assign("row",$row);
		$this->display();
	}
	function user_role_add(){
		C("debug",1);
		$db=M("user_role");
		if($db->add()){
			$this->success("用户添加成功");
		}else{
			$this->error("添加失败");
		}
	}
	function user_role_show(){//用户管理
		C("debug",1);
		$db=K("roleview");
		$row=$db->field("username,rname,title")->all();
		$this->assign("row",$row);
		$this->display();
	}
	function user_show(){
		C("debug",1);
		$db=M("user");
		$this->assign("row",$db->all());
		$this->display();
	}

	function node_add(){
		C("debug",1);
		$db=M("node");
		if($db->add()){
			$this->success("节点添加成功");
		}else{
			$this->error("添加失败");
		}
	}
	function node_show(){
		$db=M("node");
		$this->assign("row",$db->all());
		$this->display();
	}
	
	function node_add_show(){
		if(isset($_GET['nid'])){
			$db=M("node");
			$nid=$_GET['nid'];
			$row=$db->where("nid='$nid'")->find();
			$pid=$row['pid'];
			$nid=$row['nid'];
			$parent=$db->field("nid,title,name")->where("nid='$pid'")->find();
			if($parent){
				$row['title']="-->".$row['title'];
				$this->assign("parent",$parent);
			}
			$child=$db->field("nid,title,name")->where("pid='$nid'")->find();
			if($child){
				$child['title']="<--".$child['title'];
				$this->assign("child",$child);
			}
			$this->assign("row",$row);
		}
			$this->display();
	}
	function node_acc_add(){
		C("debug",1);
		$db=M("access");
		foreach ($_POST['nid'] as $k => $v) {
		 	$_POST['nid']=$v;
		 	$_POST['level']=$_POST['level']["$k"];
		 	$db->add();
	}
		if($db->get_affected_rows()){
			$this->success("添加成功");
		}else{
			$this->error("添加失败");
		}
}
	function role_node_show(){
		C("debug",1);
		$db=M("node");
		$row=$db->all();
		$rid=$_GET['rid'];
		$this->assign("row",$row);
		$this->assign("rid",$rid);
		$this->display();



	}


}


?>